package com.huan.social.weixin.connect;

import com.huan.social.weixin.api.Weixin;
import com.huan.social.weixin.api.WeixinUserInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;

/**
 * 微信 api 适配器
 *
 * @author huan.fu
 * @date 2018/9/27 - 11:34
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class WeixinAdapter implements ApiAdapter<Weixin> {

	private String openId;

	@Override
	public boolean test(Weixin api) {
		return true;
	}

	@Override
	public void setConnectionValues(Weixin api, ConnectionValues values) {
		WeixinUserInfo userInfo = api.getUserInfo(this.getOpenId());
		values.setProviderUserId(this.getOpenId());
		values.setProfileUrl(null);
		values.setImageUrl(userInfo.getHeadImageUrl());
		values.setDisplayName(userInfo.getNickname());
	}

	@Override
	public UserProfile fetchUserProfile(Weixin api) {
		return null;
	}

	@Override
	public void updateStatus(Weixin api, String message) {

	}
}
